/**
 * 
 */
package com.ms.service.module.baccarat;

import com.ms.game.slot.base.SlotGameBasicAction;
import com.ms.service.module.zone.module.BasicZoneModule;
import com.xpec.c4.service.module.task.TaskTimer;

/**
 * 百家樂遊戲 module
 * 
 * @author TW15010
 */
public class BacrGameModule extends BasicZoneModule {
	
	public static final int CHECK_VERIFY_TIME_OUT = 5 * 1000;
	
	public static final String GAME_TYPE = "BACR";

	/**
	 * 主要功能類別
	 */
	private BacrProcessor proc = new BacrProcessor();

	/**
	 * server 之間的連線是否完成
	 */
	private boolean serverConnectReady = false;

	/**
	 * 建構
	 */
	public BacrGameModule() {
		super();
		setZone(proc);
	}

	@Override
	public void init() {
		super.init();
		registerActionClass(BacrAction.class);
		
		registerActionClass(SlotGameBasicAction.class);
	}

	@Override
	public boolean startup() {

		//處理清除過期連勝紀錄
		BacrCleanCombosTaskTimer taskTimer = new BacrCleanCombosTaskTimer();
		taskTimer.setModule(this);
		taskTimer.setCronExpressions("0 0/3 * 1/1 * ? *");
		this.addCronTaskTimer(taskTimer);
		
		return super.startup();
	}

	@Override
	public void onServerConnectReady() {
		super.onServerConnectReady();
		serverConnectReady = true;
		
		//驗證入座超時
		BacrExprieVerifyTimerTask verifytask = new BacrExprieVerifyTimerTask();
		verifytask.setModuleServer(this);
		verifytask.setTimerOption(TaskTimer.LOOP);
		verifytask.setInitialDelay(CHECK_VERIFY_TIME_OUT);
		verifytask.setPeriod(CHECK_VERIFY_TIME_OUT);
		verifytask.setCallback(this);
		addTaskTimer(verifytask);
	}

	@Override
	public void onUpdateTaskTimer(long periodTime) {
		super.onUpdateTaskTimer(periodTime);

		if (serverConnectReady) {
			proc.onUpdate();
		}
	}

	public BacrProcessor getProc() {
		return proc;
	}
}
